package CalculationCore;
import MAINWIN.*;

public class CProgramThread implements Runnable{
	
	public CProgramThread(CCPUBlackBox cpuBB) {
		super();
		this.cpuBB = cpuBB;
	}

	CCPUBlackBox cpuBB;

	@Override
	public void run() {

		boolean bWasError = false;
		
		cpuBB.getCurrentProgram().setHasEOFhappened(false);
		cpuBB.getCurrentProgram().setHasNullOperationhappened(false);

		while(	cpuBB.isRunning() && !bWasError &&
				!cpuBB.getCurrentProgram().getHasEOFhappened() && 
				!cpuBB.getCurrentProgram().getHasNullOperationhappened()  )  
		{
			bWasError = cpuBB.getCurrentProgram().exeStep(cpuBB);
			//CMainForm.pModeForm.tableUpdate();
		}
		CMainForm.pModeForm.tableUpdate(); //update pointer
		if (bWasError ||
			cpuBB.getCurrentProgram().getHasEOFhappened() ||
			cpuBB.getCurrentProgram().getHasNullOperationhappened())
			CMainForm.LEDout("    error");
		else
			CMainForm.LEDout(CMainForm.getCalculator().getXToLED());
	}

}
